from pms.common.views import PostFormula
from department.models import DepartmentRole, DepartmentEmpower


class API(PostFormula):

    def handle(self, req):
        did = req['id']
        return self.success_respond({
            'list': [{
                'id': role.id,
                'name': role.name,
                'permissions': [empower.pid_id for empower in DepartmentEmpower.objects.filter(rid=role)]
            } for role in DepartmentRole.objects.filter(did_id=did)]
        })
